<?php
require 'init.php';
extract($_POST);
$result = $db -> query("SELECT * FROM `userinfo` WHERE `username` = '$username'");
$result = $result -> fetch_assoc();
if(is_null($result)){
    $db -> query("INSERT INTO `userinfo` (`id`, `username`, `password`) VALUES (NULL, '$username', '$password')");
    echo json_encode([
        'code' => 200,
        'msg' => '注册成功'
    ]);
}else{
    echo json_encode([
        'code' => 201,
        'msg' => '注册失败，用户名已被占用'
    ]);
}

?>